package com.cxx.admin.controller;

import com.cxx.admin.service.AccountService;
import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.common.dto.AccountDto;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/account")
@Tag(name = "账户管理")
public class AccountController {
    @Resource
    private AccountService accountService;

    @Operation(summary = "查询用户账号")
    @GetMapping("")
    public @JsonView(ReadView.class) List<AccountDto> queryAccountList() {
        return accountService.queryAccountList();
    }

    @Operation(summary = "注册账户")
    @PostMapping("")
    public Boolean registerAccount(@JsonView(WriteView.class) @Validated @RequestBody AccountDto accountDto) {
        return accountService.registerAccount(accountDto);
    }

    @Operation(summary = "注销账户")
    @DeleteMapping("/{id}")
    public Boolean deleteAccount(@PathVariable("id") Long id) {
        return accountService.deleteAccount(id);
    }

    @Operation(summary = "更改账户密码")
    @PutMapping("/password/{id}")
    public Boolean updateAccountPassword(@PathVariable("id") Long id,
                                         @RequestParam String oldPassword,
                                         @RequestParam String newPassword) {
        return Boolean.TRUE;
    }
}